/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.haipv.qa.dataset.wiki;

import java.io.*;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/**
 *
 * @author PHANHAI
 */
public class ReduceEnWikiDataSet {

    private static String filename = "F://DataSet/Wiki/enwiki-20130904-pages-articles1-p000000010p000010000.xml";

     public static void main(String[] args) {
         System.out.println("ABC".replaceAll("A", "_"));
     }
    
    public static void mainz(String[] args) {
        try {

            SAXParserFactory factory = SAXParserFactory.newInstance();
            SAXParser saxParser = factory.newSAXParser();

            DefaultHandler handler = new DefaultHandler() {

                boolean title = false;
                boolean text = false;

                @Override
                public void startElement(String uri, String localName,
                        String qName, Attributes attributes)
                        throws SAXException {

                    // System.out.println("Start Element :" + qName);

                    if (qName.equals("title")) {
                        title = true;
                    }

                    if (qName.equalsIgnoreCase("text")) {
                        text = true;
                    }

                }

                @Override
                public void endElement(String uri, String localName,
                        String qName)
                        throws SAXException {
                    if (qName.equalsIgnoreCase("text")) {
                        text = false;
                    }
                    //    System.out.println("End Element :" + qName);

                }

                @Override
                public void characters(char ch[], int start, int length)
                        throws SAXException {

                    // System.out.println(new String(ch, start, length));


//    	          if (title) {
//    	            System.out.println(new String(ch, start, length));
//    	            title = false;
//    	          }

                    if (text) {
                        System.out.println(new String(ch, start, length));
                        //text = false;
                    }
                }
            };

            File file = new File(filename);
            InputStream inputStream = new FileInputStream(file);
            Reader reader = new InputStreamReader(inputStream);//,"UTF-8");

            InputSource is = new InputSource(reader);
            // is.setEncoding("UTF-8");

            saxParser.parse(is, handler);


        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
